#include "OpenGLExecutant.h"

#include <glad/glad.h>

namespace Fysics
{
	void OpenGLExecutant::SetClearColor(const glm::vec4& color)
	{
		glClearColor(color.r, color.g, color.b, color.a);
	}

	void OpenGLExecutant::Clear()
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}

	void OpenGLExecutant::CloseDepthTest()
	{
		glDisable(GL_DEPTH_TEST);
	}

	void OpenGLExecutant::OpenDepthTest()
	{
		glEnable(GL_DEPTH_TEST);
	}

	void OpenGLExecutant::RenderSide(int side, int screenWidth, int screenHeight)
	{
		switch (side)
		{
		case 0:
		{
			glViewport(0, 0, screenWidth / 2, screenHeight);
			break;
		}
		case 1:
		{
			glViewport(screenWidth / 2, 0, screenWidth / 2, screenHeight);
			break;
		}
		default:
			glViewport(0, 0, screenWidth, screenHeight);
			break;
		}
		
	}

	void OpenGLExecutant::DrawIndexed(const VertexArray* vertexArray)
	{
		glDrawElements(GL_TRIANGLES, vertexArray->GetIndexBuffer()->GetCount(),
			GL_UNSIGNED_INT, nullptr);
	}

	void OpenGLExecutant::DrawLine(const VertexArray* vertexArray, float width)
	{
		vertexArray->Bind();
		glLineWidth(width);
		glDrawElements(GL_LINES, vertexArray->GetIndexBuffer()->GetCount(),
			GL_UNSIGNED_INT, nullptr);
	}

	void OpenGLExecutant::DrawPoints(const VertexArray* vertexArray, float radius)
	{
		vertexArray->Bind();
		glPointSize(radius);
		glDrawArrays(GL_POINTS, 0, vertexArray->GetVertexBuffers()[0]->GetCount());
	}
}